//
//  SYSearchView.swift
//  仿微博
//
//  Created by a。 on 16/9/20.
//  Copyright © 2016年 a。. All rights reserved.
//

import UIKit

class SYSearchView: UIView {
    
    //searchViewTextField 右边的约束
    @IBOutlet weak var searchRightConstratint: NSLayoutConstraint!
    
    @IBOutlet weak var searchBtn: UIButton!
    
    @IBOutlet weak var searchViewTextField: UITextField!
    
    
    //监听searchViewTextField的editing did  begin 事件
    
    @IBAction func searchTextFieldBeginediting(_ sender: AnyObject) {
        
        searchRightConstratint.constant = searchBtn.width + 10
        
        UIView.animate(withDuration: 0.5) {
            
            self.layoutIfNeeded()
        }
    }
    
    @IBAction func seachButtonClick(_ sender: AnyObject) {
        
        searchViewTextField.resignFirstResponder()
        searchRightConstratint.constant = 0
        //添加动画
        
        
        
        UIView.animate(withDuration: 0.5) {
            
            self.layoutIfNeeded()
        }
    }
    
    
//    //加载xib会走此方法  可以设置属性
//    override func awakeFromNib() {
//        searchViewTextField.layer.borderColor = UIColor.magenta.cgColor
//        searchViewTextField.layer.borderWidth = 2
//        searchViewTextField.layer.cornerRadius = 5
//        searchViewTextField.layer.masksToBounds = true
//    }
    
    
    //通过类方法加载xib
    class func searchView() -> SYSearchView{
        
        return UINib(nibName:"SYSearchView", bundle: nil).instantiate(withOwner: nil, options:nil).last! as! SYSearchView
    }
    
}
